<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
  <link href="${pageContext.request.contextPath}/css/style.css" rel="stylesheet" type="text/css" />
  <link href="${pageContext.request.contextPath}/layui/css/layui.css"  media="all" rel="stylesheet" type="text/css" />
  <script type=javascript src="${pageContext.request.contextPath}/layui/jquery2.1.1.js" ></script>
  <script type=javascript src="${pageContext.request.contextPath}/layui/lay/modules/table.js" ></script>
  <script type=javascript src="${pageContext.request.contextPath}/layui/lay/modules/form.js" ></script>
  <script type=javascript src="${pageContext.request.contextPath}/layui/lay/modules/layer.js" ></script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>营销管理</li>
    <li>客户管理</li>
    <li>添加</li>
  </ul>
</div>
<form class="layui-form" lay-filter="detail">
  <div class="formtitle"><span>客户信息</span></div>
  <div class="layui-form-item" >
    <label class="layui-form-label">客户姓名</label>
    <div class="layui-input-block">
      <input type="text" id="name" name="name" class="layui-input">
    </div>
  </div>

  <div class="layui-form-item" >
    <label class="layui-form-label">性别</label>
    <div class="layui-input-block">
      <input type="text" id="sex" name="sex" class="layui-input" >
    </div>
  </div>

  <div class="layui-form-item" >
    <label class="layui-form-label">所属公司名称</label>
    <div class="layui-input-block">
      <input type="text" id="company" name="company" class="layui-input" >
    </div>
  </div>

  <div class="layui-form-item" >
    <label class="layui-form-label">联系方式</label>
    <div class="layui-input-block">
      <input type="text" id="tel" name="tel" class="layui-input" >
    </div>
  </div>

  <div class="layui-form-item" >
    <label class="layui-form-label">联系地址</label>
    <div class="layui-input-block">
      <input type="text" id="address" name="address" class="layui-input" >
    </div>
  </div>

  <div class="layui-form-item" >
    <label class="layui-form-label">所属区域</label>
    <div class="layui-input-inline">
      <select name="province" id="province">
        <option value="0">请选择省份</option>
        <option value="江西省">江西省</option>
        <option value="湖北省">湖北省</option>
      </select>
    </div>
    <div class="layui-input-inline">
      <select name="city" id="city" >
        <option value="0">请选择城市</option>
        <option value="南昌市">南昌市</option>
        <option value="九江市">九江市</option>
        <option value="吉安市">吉安市</option>
      </select>
    </div>
  </div>

  <div class="layui-form-item" >
    <label class="layui-form-label">描述</label>
    <div class="layui-input-block">
      <textarea id="describe" name="describe" class="layui-input" ></textarea>
    </div>
  </div>

  <div class="layui-form-item" >
    <label class="layui-form-label">状态</label>
    <div class="layui-input-inline" >
      <select name="status" id="status" readonly>
        <option value="0">不可用</option>
        <option value="1">可用</option>
      </select>
    </div>
  </div>

  <div class="layui-form-item" >
    <label class="layui-form-label">创建人</label>
    <div class="layui-input-block">
      <input type="text" id="creater" name="creater" readonly class="layui-input" value="${sessionScope.loginUser.ename}">
    </div>
  </div>

  <div class="layui-form-item" style="display: none">
    <label class="layui-form-label">是否分配</label>
    <div class="layui-input-block">
      <input type="text" id="divide" name="divide" readonly class="layui-input" value="0">
    </div>
  </div>

  <div class="layui-form-item" >
    <label class="layui-form-label">创建时间</label>
    <div class="layui-input-block">
      <input type="text" id="createTime" name="createTime" readonly class="layui-input">
    </div>
  </div>

  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
    </div>
  </div>
</form>
<script src="https://www.layuicdn.com/layui-v2.5.6/layui.js"></script>
<script>
  layui.use('form', function () {
    var form = layui.form,
            util = layui.util,
            $ = layui.$;
    form.render();
    //监听提交
    form.on('submit(saveBtn)', function (data) {
      console.log(data.field);
      //console.log(data.field.createTime);
      var time = data.field.createTime.replaceAll("/","-");
      data.field.createTime = time;
      console.log(data.field);
      //向后台发送数据并进行添加操作
      $.ajax({
        url:"/customer/addCustomer",
        type:"POST",
        contentType:"application/json",
        data:JSON.stringify(data.field),
        success:function(operate){
          console.log(operate.message)
          if(operate.message=="用户添加成功！牛逼"){
            layer.msg("添加成功",{
              icon:6,
              time:500
            },function(){
              parent.window.location.reload();//重新页面
              var iframeIndex = parent.layer.getFrameIndex(window.name);
              parent.layer.close(iframeIndex);
            });
          }else{
            layer.msg("添加成功");
          }
        }
      })
      return false;
    });
  });
</script>
</body>
</html>
